Attribute VB_Name = "MdlMain"
Option Explicit
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Const MAX_CHUNK = 8192 'Max size of sendable data
Public bReplied As Boolean 'True if server replied
Public Destination As String

Public con As ADODB.Connection
Public rs As ADODB.Recordset
Public gs As ADODB.Recordset
Public Myname As String


Sub Main()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.ConnectionString = "Provider=microsoft.jet.oledb.4.0;data source=" & (App.Path & "\chat2.mdb") & ";persist security info=false"
con.Open
'Form1.Show

End Sub


Sub SendFile(Fname As String)
Dim DataChunk As String
Dim Passes As Long
SendData "cmd|OpenFile|" & Fname ' send over the filename so the Server knows where to store the file.
Pause 200
Open Fname For Binary As #1
  Do While Not EOF(1)
   Passes = Passes + 1
    DataChunk = Input(MAX_CHUNK, #1) 'get some of the file data, 8192 bytes, don't go bigger
    SendData DataChunk
    frmMain.Status = "Transfering... " & CStr(Len(DataChunk)) & ":::" & CStr(Passes) & " bytes"
    frmMain.Label_close.Enabled = False
    Pause 200
    DoEvents
  Loop
  SendData "cmd|CloseFile"
  frmMain.Label_close.Enabled = True
  frmMain.Status = "Connected."
Close #1
Passes = 0
End Sub

Function GetFileName(Fname As String) As String
Dim I As Integer
Dim TempStr As String
For I = 1 To Len(Fname)
  TempStr = Right(Fname, I)
  If Left(TempStr, 1) = "\" Then
    GetFileName = Mid(TempStr, 2, Len(TempStr))
    Exit Function
  End If
Next I
End Function

Function SendData(sData As String) As Boolean
Dim TimeOut As Long
On Error GoTo ErrH
bReplied = False
frmMain.wsChat.SendData sData
Do Until (frmMain.wsChat.State = 0) Or (TimeOut < 100000)
  DoEvents
  TimeOut = TimeOut + 1
  If TimeOut > 100000 Then Exit Do
Loop
SendData = True
Exit Function
    
ErrH:
    SendData = False
    MsgBox Err.Description, 16, "Error #" & Err.Number
    frmMain.Status = "Disconnected."
End Function

Sub Pause(HowLong As Long)
Dim Tick As Long
Tick = GetTickCount()
Do
  DoEvents
Loop Until Tick + HowLong < GetTickCount
End Sub




